// 定义组件
define(function (require,exports,module) {
    var alert = Vue.extend({
        template:
        '<div class="v-dialogWrap" @touchmove="onTouchMove">'+
            '<transition :name="maskTransition">'+
                '<div class="v-mask" @click="hideOnBlur && (currentValue = false)" v-show="currentValue"></div>'+
            '</transition>'+
            '<transition :name="dialogTransition">'+
                '<div class="v-dialog" v-show="currentValue" >'+
                    '<div class="v-dialog-title" v-show="title">{{titleTxt}}<i class="v-dialog-title-close iconfont icon-close" @click="currentValue=false"></i></div>'+
                    '<div class="v-dialogMain">' +
                        '<slot></slot>'+
                    '</div>'+
                    '<div class="v-dialog-btns">' +
                        '<button class="v-dialog-cancel" v-show="cancel" @click="_onCancel">{{cancelTxt}}</button>'+
                        '<button class="v-dialog-btn" v-show="confirm" @click="_onConfirm">{{confirmTxt}}</button>'+
                    '</div>'+
                '</div>'+
            '</transition>'+
        '</div>',
        props: {
            value: {
                type: Boolean,
                default: false
            },
            maskTransition: {
                type: String,
                default: 'v-mask'
            },
            dialogTransition: {
                type: String,
                default: 'v-dialog'
            },
            hideOnBlur: Boolean,
            title:{
                type: Boolean,
                default: true
            },
            titleTxt:{
                type: String,
                default: '提示'
            },
            cancelTxt:{
                type: String,
                default: '取消'
            },
            confirmTxt:{
                type: String,
                default: '确定'
            },
            cancel:{
                type:Boolean,
                default: false
            },
            confirm:{
                type:Boolean,
                default: true
            },
            scroll: {
                type: Boolean,
                default: true
            }
        },
        created:function(){
            if (typeof this.value !== 'undefined') {
                this.currentValue = this.value
            }
        },
        data(){
            return {
                currentValue:false
            }
        },
        watch: {
            value: {
                handler: function (val) {
                    this.currentValue = val
                },
                immediate: true
            },
            currentValue:function (val) {
                this.$emit(val ? 'on-show' : 'on-hide')
                this.$emit('input', val)
            }
        },
        methods: {
            onTouchMove: function (event) {
                !this.scroll && event.preventDefault()
            },
            _onConfirm () {
                this.$emit('on-confirm')
            },
            _onCancel () {
                this.currentValue = false
                this.$emit('on-cancel')
            }
        }
    });
    module.exports = alert;
});

